<?php

class g5_admin_menu_group extends Model {

    function __construct() {
        parent::__construct();
        $this->_tableName = 'g5_admin_menu_group';
    }

    function getRoles($id = 0){
        $data   = $this->getAll('*', array('menu_id' => $id));
        $result = array();
		foreach($data as $arr ){
			$result[] = $arr["group_id"];
		}
		return $result;
	}

    function assignMenuGroup($menus, $group_id){
		$this->delete(array("group_id"=>$group_id));
		if(is_array($menus)){
			foreach($menus as $menu_id){
				$this->replace(array("menu_id"=>$menu_id,"group_id"=>$group_id));
			}
			return true;
		}
        return false;
	}


	function addMenuGroup($roles){
        return $this->insert($roles);
	}

    function deleteMenuGroup($id = array()) {
        return $this->in(array('menu_id'=>$id))->delete();
    }
}